package tree;

/**
 * @author huangliusong
 * @since 2018/10/22
 * {@link }
 */
public class TreeTraversal {
    public static void main(String[] args) {
        TreeCreater creater=new TreeCreater();
        TreeTraversal treeTraversal=new TreeTraversal();
        TreeNode sample=creater.createSample();
        treeTraversal.preOrder(sample);
        System.out.println();
        treeTraversal.inOrder(sample);
        System.out.println();
        treeTraversal.backOrder(sample);

        System.out.println("\n=========");
        TreeNode treeNode=creater.createTreed("ABDEGCF","DBGEACF");
        treeTraversal.backOrder(treeNode);


    }


    public void inOrder(TreeNode root){
        if (root==null){
            return;
        }


        inOrder(root.getLeft());
        System.out.print(root.getValue());
        inOrder(root.getRight());
    }
    public void preOrder(TreeNode root){
        if (root==null){
            return;
        }

        System.out.print(root.getValue());
        preOrder(root.getLeft());
        preOrder(root.getRight());
    }


    public void backOrder(TreeNode root){
        if (root==null){
            return;
        }


        backOrder(root.getLeft());
        backOrder(root.getRight());
        System.out.print(root.getValue());
    }
}
